/* 921. 使括号有效的最少添加 */
/**
 * @param {string} s
 * @return {number}
 */

var minAddToMakeValid = function (s) {
	const stack1 = []
	const stack2 = []
	for (const str of s) {
		if (str === '(') {
			stack1.push('(')
		} else {
			if (stack1.length) {
				stack1.pop()
			} else {
				stack2.push(')')
			}
		}
	}
	return stack1.length + stack2.length
}
var minAddToMakeValid = function (s) {
	let ans = 0
	let leftCount = 0
	let length = s.length
	for (let i = 0; i < length; i++) {
		const c = s[i]
		if (c === '(') {
			leftCount++
		} else {
			if (leftCount > 0) {
				leftCount--
			} else {
				ans++
			}
		}
	}
	return ans + leftCount
}
const result = minAddToMakeValid('()')
console.log('minAddToMakeValid :>>', result)
